Add which-key-local-then-key-order
authorjustbur <justin@burkett.cc>
Mon, 16 May 2016 19:35:33 +0000 (15:35 -0400)
committerjustbur <justin@burkett.cc>
Mon, 16 May 2016 19:35:33 +0000 (15:35 -0400)
To use (setq which-key-sort-order 'which-key-local-then-key-order)

See #125

which-key.el

index b44589335964f6796a0583120a36589834aac3a2..d221c6fdcd295b2a719e0978d22249acfe54e6be 100644 (file)
@@ -1196,6 +1196,21 @@ coming before a prefix. Within these categories order using
         (and (not apref?) bpref?)
       (which-key-key-order acons bcons))))
 
+(defun which-key--local-binding-p (keydesc)
+  (eq (which-key--safe-lookup-key
+       (current-local-map) (kbd (which-key--current-key-string (car keydesc))))
+      (intern (cdr keydesc))))
+
+(defun which-key-local-then-key-order (acons bcons)
+  "Order first by whether A and/or B is a local binding with
+local bindings coming first. Within these categories order using
+`which-key-key-order'."
+  (let ((aloc? (which-key--local-binding-p acons))
+        (bloc? (which-key--local-binding-p bcons)))
+    (if (not (eq aloc? bloc?))
+        (and aloc? (not bloc?))
+      (which-key-key-order acons bcons))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Functions for retrieving and formatting keys